package com.billing.mvc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.billing.persistance.entities.Invoice;
import com.billing.service.IBillingService;
import com.billing.service.InvoiceService;

@Controller
public class InvoiceController {

    @Autowired
    private IBillingService billingService;
    
    @Autowired
    private InvoiceService invoiceService;
    
    @ModelAttribute("invoice")
    public Invoice createInvoice() {
        return new Invoice();
    }
    
    
    @RequestMapping("/invoice/view")
    public String getDetail(@RequestParam Long id, ModelMap model){
        
        Invoice invoice = invoiceService.readInvoice(id);
        
        model.addAttribute("invoice", invoice);
        
        return "invoice";
    }
    
    
    @RequestMapping("/invoice/report")
    public String generateReport(@RequestParam Long id, ModelMap model){
        
    	Invoice invoice = invoiceService.readInvoice(id);
    	System.out.println("Invoice to render as PDF: ");
    	System.out.println(invoice	);
    	model.put("invoice", invoice);
    	
        return "PdfInvoice";
    }
    
    
}

